//
//  UserTool.swift
//  LCYWeiBo
//
//  Created by 李长友 on 16/9/5.
//  Copyright © 2016年 app. All rights reserved.
//

import UIKit

class UserViewModel {
    
    static let shareInstance = UserViewModel()
    
    var user: UserModel?
    
    var userPath: String {
        
        return NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true).first! + "/userModel.plist"
    }
    
    var isLogin: Bool {
        
        get {
            guard let user = user else {
                return false
            }
            
            guard let expires_date = user.expires_date else {
                return false
            }
            
            return expires_date.compare(NSDate()) == NSComparisonResult.OrderedDescending
        }
        
        set {
            self.isLogin = newValue
        }
    }
    
    init() {
        user = NSKeyedUnarchiver.unarchiveObjectWithFile(userPath) as? UserModel
    }
}
